// EntitySetOperation.cpp: implementation of the EntitySetOperation class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
//#include "resource.h"
#include "EntitySetOperation.h"
#include "SingleEntityOperation.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

EntitySetOperation::EntitySetOperation()
{

}

EntitySetOperation::~EntitySetOperation()
{

}

void EntitySetOperation::Add(AcDbHandle& EntityHandle)
{
	ASSERT(!EntityHandle.isNull());

	if(m_HandleList.Find(EntityHandle) != NULL)
	{
		return ;
	}
	m_HandleList.AddTail(EntityHandle);

}

void EntitySetOperation::Remove(AcDbHandle& EntityHandle)
{
	ASSERT(!EntityHandle.isNull());
	POSITION pos = m_HandleList.Find(EntityHandle);
	ASSERT(pos !=NULL);
	
	m_HandleList.RemoveAt(pos);
}

Acad::ErrorStatus EntitySetOperation::TransformBy(AcGeMatrix3d &matrix)
{
	ASSERT(!m_HandleList.IsEmpty());
	
	SingleEntityOperation EntityOp;
	Acad::ErrorStatus nState= Acad::eOk;
	POSITION pos = m_HandleList.GetHeadPosition();
	for(int i = 0; i< m_HandleList.GetCount() ;i++)
	{
		AcDbHandle EntityHandle = m_HandleList.GetNext(pos);

		if((nState = EntityOp.TransformBy(EntityHandle , matrix))
			!= Acad::eOk)
			return nState;
	}

	return nState;
}

Acad::ErrorStatus EntitySetOperation::HightLight()
{
	ASSERT(!m_HandleList.IsEmpty());
	
	SingleEntityOperation EntityOp;
	Acad::ErrorStatus nState= Acad::eOk;
	POSITION pos = m_HandleList.GetHeadPosition();
	for(int i = 0; i< m_HandleList.GetCount() ;i++)
	{
		AcDbHandle EntityHandle = m_HandleList.GetNext(pos);

		if((nState = EntityOp.HightLight(EntityHandle))
			!= Acad::eOk)
			return nState;
	}

	return nState;
}